﻿using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using SlamCms.SharePoint.Core;


namespace SlamCms.SharePoint.Publishing.WebParts
{




    [ToolboxItemAttribute(false)]
    public class PublisherManager : WebPart
    {

        private int _pageSize = 20;
        [Personalizable(PersonalizationScope.Shared),
         WebBrowsable(true),
         Category("Content Display Settings"),
         WebDisplayName("Number of items per page")]
        public int PageSize
        {
            get
            {
                return _pageSize;
            }
            set
            {
                _pageSize = value;
            }
        }

        private string _keywords = "";
        [Personalizable(PersonalizationScope.Shared),
         WebBrowsable(true),
         Category("Content Display Settings"),
         WebDisplayName("Keywords use to identified sharepoint groups")]
        public string Keywords
        {
            get
            {
                return _keywords;
            }
            set
            {
                _keywords = value;
            }
        }

        // Visual Studio might automatically update this path when you change the Visual Web Part project item.
        private const string _ascxPath = @"~/_CONTROLTEMPLATES/SlamCms.SharePoint.Publishing.WebParts/PublisherManager/PublisherManager.ascx";

        protected override void CreateChildControls()
        {
            PublisherManagerControl control = Page.LoadControl(_ascxPath) as PublisherManagerControl;
            control.Keywords = this.Keywords;
            control.PageSize = this.PageSize;
            Controls.Add(control);
        }

        protected override void OnEditModeChanged(EventArgs e)
        {
            SlamCmsContext.Data.Cache.InvalidateUsers();
            SlamCmsContext.Data.Cache.InvalidateCore();
            SlamCmsContext.Data.Cache.InvalidateTags();
        }
    }
}
